package top.lyjwn.todo.weinxin.api.applet;

import com.alibaba.fastjson2.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import top.lyjwn.todo.weinxin.api.url.WXAppletUrl;
import top.lyjwn.todo.common.utils.http.HttpUtil;

/**
 * 获取小程序全局唯一后台接口调用凭据（access_token）。调调用绝大多数后台接口时都需使用 access_token，开发者需要进行妥善保存。
 *
 * @author luoyujie
 *
 */
@Component
public class AuthGetAccessToken {

	@Autowired
	private WXAppletUrl wxAppletUrl;

	public String getUrl() {

		String url = wxAppletUrl.getAUTH_GET_ACCESS_TOKEN();
		return url;
	}

	public String getResultString() {
		String result = HttpUtil.request(this.getUrl(), HttpUtil.METHOD_GET);
		return result;
	}

	public JSONObject getResultJSONObject()
	{
		String resultString = this.getResultString();
		return JSONObject.parseObject(resultString);
	}

}
